package com.ea.framework.config;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ea.repository.entity.SysConfig;
import com.ea.repository.entity.SysConfigExample;
import com.ea.repository.mapper.SysConfigMapper;
import com.ea.util.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * @ClassName SysConfigLoader
 * @Description TODO
 * @Author XIONG CAI
 * @Date 2024/11/12
 */
@Component
public class SysConfigLoader {
    @Autowired
    private SysConfigMapper sysConfigMapper;
    @Autowired
    private RedisUtils redisUtils;


    @PostConstruct
    public void init() {
        QueryWrapper<SysConfig> queryWrapper = new QueryWrapper<SysConfig>().eq("is_delete", 0);
        List<SysConfig> sysConfigList = sysConfigMapper.selectList(queryWrapper);
        // 在这里编写你的启动逻辑
        System.out.println("-----自动加载系统配置信息，数量：" + sysConfigList.size());
        /***将系统配置信息加载导Redis中***/
        Map<String, String> configMap = sysConfigList.stream().collect(Collectors.toMap(SysConfig::getConfigName, SysConfig::getConfigValue));
        redisUtils.batchSet(configMap);
        System.out.println("-----自动加载系统配置信息完成-----");
    }
}
